home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / deleteln.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.9 KB  |  304 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    deleteln
  24. #undef    wdeleteln
  25. #undef    insdelln
  26. #undef    winsdelln
  27. #undef    insertln
  28. #undef    winsertln
  29.  
  30. /* undefine any macros for functions called by this module if in debug mode */
  31. #ifdef PDCDEBUG
  32. #endif
  33.  
  34. #ifdef PDCDEBUG
  35. char *rcsid_deleteln  = "$Id$";
  36. #endif
  37.  
  38. /*man-start*********************************************************************
  39.  
  40.   Name:                                                      deleteln
  41.  
  42.   Synopsis:
  43.       int deleteln(void);
  44.       int wdeleteln(WINDOW *win);
  45.       int insdelln(int n);
  46.       int winsdelln(WINDOW *win, int n);
  47.       int insertln(void);
  48.       int winsertln(WINDOW *win);
  49.  
  50.   X/Open Description:
  51.      With the deleteln() and wdelteln() functions,
  52.      the line under the cursor in the window is deleted.  All
  53.      lines below the current line are moved up one line.  The
  54.      bottom line of the window is cleared.  The cursor position
  55.      does not change.
  56.  
  57.      With the insertln() and winsertn() functions,
  58.      a blank line is inserted above the current line and the bottom
  59.      line is lost.
  60.  
  61.      NOTE: deleteln() and insertln() are implemented as macros.
  62.  
  63.   X/Open Return Value:
  64.      All functions return OK on success and ERR on error.
  65.  
  66.   X/Open Errors:
  67.      No errors are defined for this function.
  68.  
  69.   NOTE:
  70.      The behaviour of Unix curses is to clear the line with a space
  71.      and attributes of A_NORMAL. PDCurses clears the line with the
  72.      window's current attributes (including current colour). To get
  73.      the behaviour of PDCurses, #define PDCURSES_WCLR in curses.h or
  74.      add -DPDCURSES_WCLR to the compile switches.
  75.  
  76.   Portability                             X/Open    BSD    SYS V
  77.                                           Dec '88
  78.       deleteln                              Y        Y       Y
  79.       wdeleteln                             Y        Y       Y
  80.       insdelln                              -        -      4.0
  81.       winsdelln                             -        -      4.0
  82.       insertln                              Y        Y       Y
  83.       winsertln                             Y        Y       Y
  84.  
  85. **man-end**********************************************************************/
  86.  
  87. /***********************************************************************/
  88. int    deleteln(void)
  89. /***********************************************************************/
  90. {
  91.     chtype    blank;
  92.     chtype*    end;
  93.     chtype*    temp;
  94.     chtype*    ptr;
  95.     int    y;
  96.  
  97. #ifdef PDCDEBUG
  98.     if (trace_on) PDC_debug("deleteln() - called\n");
  99. #endif
  100.  
  101.     if (stdscr == (WINDOW *)NULL)
  102.         return( ERR );
  103.  
  104. #if defined(PDCURSES_WCLR)
  105.     blank    = stdscr->_blank | stdscr->_attrs;
  106. #else
  107. /* wrs (4/10/93) account for window background */
  108.     blank    = stdscr->_bkgd;
  109. #endif
  110.     temp    = stdscr->_y[stdscr->_cury];
  111.  
  112.     for (y = stdscr->_cury; y < stdscr->_bmarg; y++)
  113.     {
  114.         stdscr->_y[y]     = stdscr->_y[y + 1];
  115.         stdscr->_firstch[y] = 0;
  116.         stdscr->_lastch[y] = stdscr->_maxx - 1;
  117.     }
  118.  
  119.     for (ptr = temp; (ptr - temp < stdscr->_maxx); ptr++)
  120.         *ptr = blank;            /* make a blank line */
  121.  
  122.     if( stdscr->_cury <= stdscr->_bmarg ) 
  123.     {
  124.         stdscr->_firstch[stdscr->_bmarg]    = 0;
  125.         stdscr->_lastch[stdscr->_bmarg]    = stdscr->_maxx - 1;
  126.         stdscr->_y[stdscr->_bmarg]        = temp;
  127.     }
  128.  
  129.     return( OK );
  130. }
  131. /***********************************************************************/
  132. int    wdeleteln(WINDOW *win)
  133. /***********************************************************************/
  134. {
  135.     chtype    blank;
  136.     chtype*    end;
  137.     chtype*    temp;
  138.     chtype*    ptr;
  139.     int    y;
  140.  
  141. #ifdef PDCDEBUG
  142.     if (trace_on) PDC_debug("wdeleteln() - called\n");
  143. #endif
  144.  
  145.     if (win == (WINDOW *)NULL)
  146.         return( ERR );
  147.  
  148. #if defined(PDCURSES_WCLR)
  149.     blank    = win->_blank | win->_attrs;
  150. #else
  151. /* wrs (4/10/93) account for window background */
  152.     blank    = win->_bkgd;
  153. #endif
  154.     temp    = win->_y[win->_cury];
  155.  
  156.     for (y = win->_cury; y < win->_bmarg; y++)
  157.     {
  158.         win->_y[y]     = win->_y[y + 1];
  159.         win->_firstch[y] = 0;
  160.         win->_lastch[y] = win->_maxx - 1;
  161.     }
  162.  
  163.     for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
  164.         *ptr = blank;            /* make a blank line */
  165.  
  166.     if( win->_cury <= win->_bmarg ) 
  167.     {
  168.         win->_firstch[win->_bmarg]    = 0;
  169.         win->_lastch[win->_bmarg]    = win->_maxx - 1;
  170.         win->_y[win->_bmarg]        = temp;
  171.     }
  172.  
  173.     return( OK );
  174. }
  175. /***********************************************************************/
  176. int    insdelln(int n)
  177. /***********************************************************************/
  178. {
  179. #ifdef PDCDEBUG
  180.     if (trace_on) PDC_debug("insdelln() - called\n");
  181. #endif
  182.  
  183.     if (stdscr == (WINDOW *)NULL)
  184.         return( ERR );
  185.  
  186.     return(winsdelln(stdscr,n));
  187. }
  188. /***********************************************************************/
  189. int    winsdelln(WINDOW *win, int n)
  190. /***********************************************************************/
  191. {
  192.     int i;
  193.  
  194. #ifdef PDCDEBUG
  195.     if (trace_on) PDC_debug("winsdelln() - called\n");
  196. #endif
  197.  
  198.     if (win == (WINDOW *)NULL)
  199.         return( ERR );
  200.  
  201.     if( n > 0 ) {
  202.         for(i=0; i<n; i++) {
  203.             if( winsertln(win) == ERR )
  204.                 return ERR;
  205.         }
  206.     }
  207.     else if( n < 0 ) {
  208.         n = -n;
  209.         for(i=0; i<n; i++) {
  210.             if( wdeleteln(win) == ERR )
  211.                 return ERR;
  212.         }
  213.     }
  214.  
  215.     return( OK );
  216. }
  217. /***********************************************************************/
  218. int    insertln(void)
  219. /***********************************************************************/
  220. {
  221.     chtype    blank;
  222.     chtype*    temp;
  223.     chtype*    end;
  224.     short    y;
  225.  
  226. #ifdef PDCDEBUG
  227.     if (trace_on) PDC_debug("insertln() - called\n");
  228. #endif
  229.  
  230.     if (stdscr == (WINDOW *)NULL)
  231.         return( ERR );
  232.  
  233. #if defined(PDCURSES_WCLR)
  234.     blank    = stdscr->_blank | stdscr->_attrs;
  235. #else
  236. /* wrs (4/10/93) account for window background */
  237.     blank    = stdscr->_bkgd;
  238. #endif
  239.     temp    = stdscr->_y[stdscr->_maxy-1];
  240.  
  241.     for (y = stdscr->_maxy-1; y > stdscr->_cury; y--)
  242.     {
  243.         stdscr->_y[y]     = stdscr->_y[y - 1];
  244.         stdscr->_firstch[y] = 0;
  245.         stdscr->_lastch[y] = stdscr->_maxx - 1;
  246.     }
  247.  
  248.     stdscr->_y[stdscr->_cury] = temp;
  249.  
  250.     for (end = &temp[stdscr->_maxx - 1]; temp <= end; temp++)
  251.     {
  252.         *temp = blank;
  253.     }
  254.  
  255.     stdscr->_firstch[stdscr->_cury] = 0;
  256.     stdscr->_lastch[stdscr->_cury] = stdscr->_maxx - 1;
  257.  
  258.     return( OK );
  259. }
  260. /***********************************************************************/
  261. int    winsertln(WINDOW *win)
  262. /***********************************************************************/
  263. {
  264.     chtype    blank;
  265.     chtype*    temp;
  266.     chtype*    end;
  267.     short    y;
  268.  
  269. #ifdef PDCDEBUG
  270.     if (trace_on) PDC_debug("winsertln() - called\n");
  271. #endif
  272.  
  273.     if (win == (WINDOW *)NULL)
  274.         return( ERR );
  275.  
  276. #if defined(PDCURSES_WCLR)
  277.     blank    = win->_blank | win->_attrs;
  278. #else
  279. /* wrs (4/10/93) account for window background */
  280.     blank    = win->_bkgd;
  281. #endif
  282.     temp    = win->_y[win->_maxy-1];
  283.  
  284.     for (y = win->_maxy-1; y > win->_cury; y--)
  285.     {
  286.         win->_y[y]     = win->_y[y - 1];
  287.         win->_firstch[y] = 0;
  288.         win->_lastch[y] = win->_maxx - 1;
  289.     }
  290.  
  291.     win->_y[win->_cury] = temp;
  292.  
  293.     for (end = &temp[win->_maxx - 1]; temp <= end; temp++)
  294.     {
  295.         *temp = blank;
  296.     }
  297.  
  298.     win->_firstch[win->_cury] = 0;
  299.     win->_lastch[win->_cury] = win->_maxx - 1;
  300.  
  301.     return( OK );
  302. }
  303.